Managing Terraform Runs from the Lazsa Platform Interface

You can add, execute, and manage your Terraform runs from a deployment stage within a feature of your product in the Lazsa Platform.

This topic provides a comprehensive guide on managing Terraform runs from the Lazsa interface, the necessary prerequisites, detailed steps for setting up and executing runs, and how to monitor and control the process from start to finish.

Contents

Before you begin

To successfully execute Terraform runs from within the Lazsa Platform, ensure the following prerequisites are met:

  • Terraform Cloud workspace settings
    In the general settings of your Terraform workspace, select the appropriate execution mode (Organization Default, Remote, or Local). Also, disable the following auto-apply settings.

    • Auto-apply API, CLI, & VCS Runs

    • Auto-apply run triggers

    When you disable these options in Terraform, you see the confirmation options for your Terraform runs in Lazsa. You can either confirm and execute the run from the platform interface, or discard it if required.

  • Connection details in Lazsa
    Save the connection details of your Terraform Cloud instance that you want to access for executing runs from within the Lazsa Platform. See Configure Terraform Connection Details.

    To run Terraform scripts using your Git repository, save the connection details of your desired repository tool.
    See Configure Source Code Repository Connection Details.

    Also, create a configuration by selecting the repositories that you want to use to execute Terraform runs.
    See the Terraform with a source code repository section in the Configure Terraform Connection Details topic.

  • Jenkins connection
    The Lazsa Platform uses Jenkins to execute your Terraform runs. Save the connection details of your Jenkins account.
    See Configure Connection Details of DevOps CI/CD Pipeline Tool.

  • Deployment stage configuration
    While configuring a deployment stage within a product feature, select the following in the stage configuration:

    • Terraform deployment mode

    • The desired Terraform connection configuration

    • The desired continuous integration tool configuration

  • Terraform scripts
    You can execute and manage your Terraform scripts from the Lazsa Platform interface. Ensure that your scripts are prepared and ready for execution. Also, the credentials passed through the Terraform scripts must have the necessary privileges to provision the required infrastructure resources. For example, if the script is designed to create, modify, or delete resources (such as EC2 instances in AWS), the credentials provided must have the appropriate permissions in the target environment to successfully execute these operations. Without the correct permissions, the script may fail to provision infrastructure or make changes.

Supported methods of Terraform script execution

On the Deployment tab of a deployment stage, on the Terraform Service tab, click +New Run. Depending on whether you want to run a script using your configured Terraform Cloud workspace or from a Git repository, click the following options:

  • Terraform Workspace

    In this method, you utilize your pre-configured Terraform Cloud workspace, which is already linked to your VCS provider, working directory, and execution settings. In this method, Terraform Cloud handles state management. From Lazsa, you can trigger these Terraform runs, allowing you to manage and monitor the creation, modification, and deletion of resources from the platform interface.

    Creating a new Terraform run execution from Lazsa

  • Terraform Script from Git Repo

    This method allows you to run Terraform scripts stored in your Git repository by integrating with Jenkins. You can run Terraform scripts stored in your Git repository by using the following execution methods:

    • Standalone: In this mode, Jenkins pulls the code from the Git repository and executes Terraform scripts directly.

    • Terraform Cloud: In this mode, you can use Jenkins in conjunction with Terraform Cloud, where the scripts are executed within a Terraform Cloud workspace. Here, your local or on-premises resources, such as memory and CPU, are not consumed during the execution process as Terraform Cloud handles the entire execution in its environment.

    In the method, it is your responsibility to manage the execution process, state files, and CI/CD flow. This gives you maximum flexibility.

Executing Terraform runs via Terraform Cloud workspace

If you select the Terraform Workspace option to create a Terraform run execution, on the Terraform Workspace screen, do the following:

  1. Provide name
    Provide a unique and descriptive name to your Terraform run execution. This execution acts as an umbrella under which you can execute multiple related Terraform runs within a workspace. This helps in managing your runs better.
    For example, let's use an execution to manage runs to create an EC2 instance by creating a VPC, and an ELB in an AWS Account. Let's name this execution as VPC-EC2-ELB-DataStreamPro.

  2. Select Terraform instance
    Select the desired Terraform Cloud instance from the list of configured instances. Ensure that this instance is active and accessible from within the Lazsa Platform.

  3. Get workspaces
    To fetch all available workspaces from the selected Terraform Cloud instance, click Get Workspaces.

  4. Select workspace
    From the list of fetched workspaces, select the one you wish to use for this run execution. For example, select the workspace VPC_AWS_DataStreamPro. This Terraform workspace has already been duly configured with your VCS provider details, working directory, execution mode, and other necessary settings.

    Creating Terraform workspace run

  5. Add execution
    To add the execution entry and execute it later, click Add.

    Add Terraform run execution

    To execute the run immediately, click Execute, provide a name to your Terraform run, and proceed to execute it.

  6. Managing execution
    After you add a run execution, it is listed on the Terraform Service tab.
    Terraform run execution added

    Click Execute and then provide a name to the run. Let's call it Run-1.
    Provide name to Terraform run

  7. After you execute the run, the run ID, run name, and the name of the user who executed the run are displayed along with the initial status Plan Queued.

    Terraform run executed

  8. As the Terraform run proceeds, the status keeps changing as listed in the following table. Click the button to refresh the run status and view the latest information.

    Run Status Meaning
    Plan Queued This status denotes the pending stage of the plan run. Terraform Cloud processes each workspace's runs in the order they were queued and a run remains queued until every run before it has completed in Terraform Cloud.
    Planning The plan is in progress.
    Planned and Finished The plan succeeded with no changes. The run output already matches the current infrastructure state, so Terraform apply doesn't need to do anything.
    Planned

    The plan succeeded and the run may proceed to the apply stage.

    If the auto-apply setting is enabled on your Terraform workspace, the run automatically proceeds to the apply stage.

    If the auto-apply setting is disabled on your Terraform workspace, the run needs confirmation from the operator.

    • To proceed with the run, click Confirm and Apply.
      Terraform run needs confirmation from operator

    • To reject the apply, click Discard Run.
      If you discard the run, the run status changes to Discarded. This means you chose not to continue this run.

    Apply Queued This status denotes the pending stage of the apply run. A run remains queued until every run before it has completed in Terraform Cloud.
    Applying The Terraform apply is in progress, which means the actions proposed in your plan to create, update, or delete resources are being executed.
    Applied The run was successfully applied, which means resources were created, updated, or destroyed as specified in your plan.
    Errored The run execution failed. You can check the error details and take appropriate action.

     

    Note:

    You cannot destroy a Terraform Cloud workspace run from the Lazsa Platform interface. You can destroy it from the Terraform Cloud interface.

  9. Show runs triggered from Lazsa
    Turn on this toggle to view only the records of runs that have been executed through the Lazsa Platform in the specified Terraform Cloud workspace. When this option is disabled , you see records of all runs including those executed externally as well as those initiated through Lazsa. This option helps in managing and maintaining a clear overview of Terraform operations conducted through Lazsa, making it easier to monitor and control your infrastructure changes.

  10. More actions

    Additionally, click the ellipsis (...) adjacent to the accordion to perform the following actions:

    1. View resource summary
      After the run shows the Applied status, click the ellipsis in the upper right corner of your execution, and then click Get Resources to view details of all the resources that were created, updated, or deleted during the run. This screen provides a comprehensive list of each resource, including key attributes such as resource type, IDs, and configurations. This allows you to easily review and verify the infrastructure changes made by the Terraform run, ensuring everything has been provisioned as expected.

      If any Kubernetes clusters are created during the run, the details of those clusters are shown on the resources summary screen. You can use these Kubernetes clusters for your technology deployments through the Lazsa Platform.

      Details of reources created, updated, or deleted through Terraform run

    2. Remove execution

      Click this option to remove the execution details from the Lazsa Platform interface. You can still access your run details from the Terraform Cloud UI.


Executing Terraform runs using a Git repository

If you select the Terraform Script from Git Repo option to create a Terraform run, on the Terraform Script from Git Repo screen, do the following:

  1. Provide name
    Provide a unique name to your Terraform run execution. This run execution acts as an umbrella under which you can execute multiple related Terraform runs within a workspace. This helps in managing your runs better. For example, we will use this execution to manage runs to deploy an NGINX server on an EC2 instance by creating a VPC, and an ELB in an AWS Account. Let us name this execution as VPC-EC2-ELB-DataStreamPro.

  2. Select configured script source
    In the Configured Script Source list, select the desired configuration. While configuring a deployment stage, you must select the required Terraform script source configurations. Then the Configured Script Source list shows all the available source code repository configurations created for Terraform run execution.
    See the Terraform with a source code repository section in the Configure Terraform Connection Details topic.

  3. Select repository that contains Terraform code
    The Select Repo list shows all the available repositories from the selected script source configuration. Select the desired repository that contains your Terraform script and which you want to use for script execution.

  4. Specify working directory
    Specify the working directory within the selected source code repository. This is the directory from which the Terraform command is executed. This defaults to the root of your repository and is typically set to a subdirectory matching the environment when multiple environments exist within the same repository.

  5. Select source code branch
    Select the desired branch of your Git repository where your Terraform script is located.

  6. Select Terraform version
    Select a version of Terraform that should be used to run your script. By specifying the Terraform version in Lazsa, you ensure that your script runs consistently and as intended, avoiding any potential issues or incompatibilities that could arise if a different version were used.

  7. Terraform Script Execution Mode

    Depending on your requirement and preference, choose one of the following options and follow the next steps mentioned in the respective sections.

    Standalone (To run Terraform scripts directly using Git with Jenkins)

    Terraform Cloud (To use Terraform Cloud only for script execution)

Thus, managing Terraform runs through the Lazsa Platform offers a powerful and flexible way to automate and control your infrastructure deployments. Whether you’re leveraging Terraform Cloud or integrating with a Git repository and Jenkins, you can seamlessly manage your Terraform scripts, monitor execution status, and maintain complete oversight of your infrastructure, all within a single, cohesive platform.

Related Topics Link IconRecommended Topics